package cn.xfdzx.android.apps.shop.presenter;

import cn.xfdzx.android.apps.shop.base.BasePresenter;
import cn.xfdzx.android.apps.shop.bean.ShopInDetailsBeen;
import cn.xfdzx.android.apps.shop.bean.StoreAmountBean;
import cn.xfdzx.android.apps.shop.contract.MyShopCenterContract;
import cn.xfdzx.android.apps.shop.model.ShopInDetailsModel;
import cn.xfdzx.android.apps.shop.net.RxScheduler;
import io.reactivex.functions.Consumer;

/**
 * @author zf
 * @date 2020/6/4.
 * Description：
 */
public class MyShopCenterPresenter extends BasePresenter<MyShopCenterContract.View> implements MyShopCenterContract.Presenter {

    private MyShopCenterContract.Model model;

    public MyShopCenterPresenter() {
        model = new ShopInDetailsModel();
    }


    @Override
    public void shop_in_details() {
        if (!isViewAttached()) {
            return;
        }
        mView.showLoading();
        model.shop_in_details( )
                .compose(RxScheduler.<ShopInDetailsBeen>Flo_io_main())
                .as(mView.<ShopInDetailsBeen>bindAutoDispose())
                .subscribe(new Consumer<ShopInDetailsBeen>() {
                    @Override
                    public void accept(ShopInDetailsBeen bean) throws Exception {
                        mView.onSuccess(bean);
                        mView.hideLoading();
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        mView.onError(throwable);
                        mView.hideLoading();
                    }
                });
    }

    @Override
    public void getStoreAmount(String store_id) {
        if (!isViewAttached()) {
            return;
        }
        mView.showLoading();
        model.getStoreAmount(store_id )
                .compose(RxScheduler.<StoreAmountBean>Flo_io_main())
                .as(mView.<StoreAmountBean>bindAutoDispose())
                .subscribe(new Consumer<StoreAmountBean>() {
                    @Override
                    public void accept(StoreAmountBean bean) throws Exception {
                        mView.getStoreAmountSuccess(bean);
                        mView.hideLoading();
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        mView.onError(throwable);
                        mView.hideLoading();
                    }
                });
    }
}
